package com.hzhr.iot.web.controller;

import com.hzhr.iot.web.model.response.BaseResponse;
import com.hzhr.iot.web.util.StringHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "系统接口", description = "系统接口")
@RestController
@RequestMapping("/sys")
public class SysController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @ApiOperation("新增PV")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "userid", value = "用户编号", dataType = "Integer", required = true, paramType = "query"),
            @ApiImplicitParam(name = "useragent", value = "浏览器", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "controller", value = "controller", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "action", value = "action", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "url", value = "url", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "sourceurl", value = "来源URL", dataType = "String", required = false, paramType = "query"),
            @ApiImplicitParam(name = "requesttype", value = "请求类型 0  http请求 1 Ajax请求", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "identifxication", value = "用户标示", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "host", value = "主机名", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "sessionid", value = "会话标识", dataType = "String", required = false, paramType = "query"),
    })
    @PostMapping("addpv")
    BaseResponse addPV(@RequestParam(value = "uat", required = true) String uat
            , @RequestParam(value = "userid", required = true, defaultValue = "0") Integer userid
            , @RequestParam(value = "useragent", required = true) String useragent
            , @RequestParam(value = "controller", required = false, defaultValue = "") String controller
            , @RequestParam(value = "action", required = false, defaultValue = "") String action
            , @RequestParam(value = "url", required = true) String url
            , @RequestParam(value = "sourceurl", required = false, defaultValue = "") String sourceurl
            , @RequestParam(value = "requesttype", required = true, defaultValue = "0") Integer requesttype
            , @RequestParam(value = "identifxication", required = true) String identifxication
            , @RequestParam(value = "host", required = true) String host
            , @RequestParam(value = "sessionid", required = false, defaultValue = "") String sessionid) {
        return new BaseResponse("成功");
    }


    @ApiOperation(value = "根据字典类型获取字典列表", notes = "根据字典类型获取字典列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "typecode", value = "字典类型", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/getoptionbytypecode", method = RequestMethod.POST)
    BaseResponse getOptionByTypecode(@RequestParam(value = "typecode") String typecode) {
        if (StringHelper.isTrimEmpty(typecode)) {
            return new BaseResponse("120", "字典类型不能为空");
        }

        List<Map<String, Object>> options = new ArrayList<>();
        if (typecode.equals("C_SBZQ")) {
            Map<String, Object> item = new HashMap<>();
            item.put("id", 54);
            item.put("typename", "上报周期");
            item.put("typecode", "C_SBZQ");
            item.put("name", "每日上报");
            item.put("code", "10000361");
            item.put("isvalid", 1);
            options.add(item);
            Map<String, Object> item1 = new HashMap<>();
            item1.put("id", 55);
            item1.put("typename", "上报周期");
            item1.put("typecode", "C_SBZQ");
            item1.put("name", "每小时上报");
            item1.put("code", "10000372");
            item1.put("isvalid", 1);
            options.add(item1);
        }

        return new BaseResponse("0", "成功", options);
    }

}
